define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'product/listo/index' + location.search,
                    // add_url: 'product/listo/add',
                    // edit_url: 'product/listo/edit',
                    // del_url: 'product/listo/del',
                    // multi_url: 'product/listo/multi',
                    // import_url: 'product/listo/import',
                    table: 'product_listo',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'product_id', title: __('Product_id')},
                        {
                            field: 'product_name',
                            title: __('商品名称'),
                            operate: false,
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {field: 'num', title: __('数量')},
                        // {field: 'order_id', title: __('Order_id')},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'price', title: __('价格'), operate: 'BETWEEN'},
                        {field: 'parameters', title: __('规格'), operate: false},
                        // {field: 'iscomment', title: __('Iscomment'), operate: false},
                        {field: 'total', title: __('商品总额'), operate: 'BETWEEN'},
                        // {field: 'tag', title: __('Tag'), operate: false, formatter: Table.api.formatter.flag},
                        {field: 'toolid', title: __('Toolid'), operate: false},
                        {field: 'tool', title: __('Tool'), operate: false},
                        {field: 'send_name', title: __('Send_name'), operate: false},
                        {field: 'send_contact', title: __('Send_contact'), operate: false},
                        {field: 'send_address', title: __('Send_address'), operate: false},
                        // {field: 'createtime', title: __('下单时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'pay_time',
                            title: __('下单时间'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'send_time',
                            title: __('Send_time'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'finish_time',
                            title: __('Finish_time'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'status',
                            title: __('状态'),
                            searchList: {
                                "1": __('已下单'),
                                "5": __('待结算'),
                                "6": __('已结算'),
                                "10": __('已发货'),
                                "20": __('已完成')
                            },
                            formatter: Table.api.formatter.status
                        },
                        // {field: 'order.order_id', title: __('Order.order_id'), operate: false},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'send',
                                    text: __('发货'),
                                    title: __('发货'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    // icon: 'fa fa-angellist',
                                    url: 'product/Listo/send?id={id}',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    },
                                    disable: function (row) {
                                        var index = [1, 6].indexOf(row.order.status);
                                        if (index >= 0 && row.order.is_trans == 1) {
                                            return false;
                                        } else {
                                            return true;
                                        }
                                    },
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
